﻿using crip.Database;
using crip.Services.Repositorys;
using Microsoft.Data.SqlClient;

namespace crip.Services
{
       
    public class CheckStatusServices:ICheckStatusServices
    {
        public async Task CheckEventStatus()
        {
            
            try
            {
                SqlConnection connection = null;
                SqlCommand command = null;
                connection = new SqlConnection("Server=121.36.2.128;Database=CripDb;User ID=sa;Password=asqmkj147@");
                command = new SqlCommand($"Update Events set state = 1 where state = 0 and  Starttime < (select CONVERT(varchar, GETDATE(), 20)) Update Events set state = 2 where state = 1 and EndTime< (select CONVERT(varchar, GETDATE(),20))", connection);
                connection.Open();
                int numrows = command.ExecuteNonQuery();
                Console.WriteLine("Event更新成功条数:"+numrows);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}
